﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterPages_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PreRender += new EventHandler(InitPage);
        }
    }


    protected void InitPage(object sender, EventArgs e)
    {
        InitData();
    }

    protected void InitData()
    {
        //// Get all delivery ids of today
        //String sqlDeliveryIdList = "SELECT delivery.id as delivery_id,delivery_date from delivery where datediff(day,delivery_date,getdate())=0";
        //DataSet ds_deliverylist = DB.QuerySelect(sqlDeliveryIdList);

        //float pay = 0;
        //float get = 0;
        //float extra = 0;
        //String info = "收回\t付出\t盈余\t时间\n";
        //for (int i = 0; i < ds_deliverylist.Tables[0].Rows.Count; i++)
        //{
        //    String[] report = DB.GetDeliveryReport(ds_deliverylist.Tables[0].Rows[i].ItemArray[0].ToString());

        //    get += float.Parse(report[0]);
        //    pay += float.Parse(report[1]);
        //    extra += float.Parse(report[2]);
        //    info += report[0] + "\t" + report[1] + "\t" + report[2] + "\t" + ds_deliverylist.Tables[0].Rows[i].ItemArray[1].ToString() + "\n";
        //}

        //info += "总计:\n" + get + "-" + pay + " = " + extra;

        //detail_order_textbox.Text = info;

        ////String sqlLuckyCourier = "SELECT courier.id as courier_id,code,name FROM courier WHERE courier.id in " +
        ////                        "(SELECT courier_id from delivery where checked=0)";

        ////DataSet ds_luckycourier = DB.QuerySelect(sqlLuckyCourier);
        ////luckycourier_datagrid.DataSource = ds_luckycourier;
        ////luckycourier_datagrid.DataBind();
    }


    //protected void OnClickDetailBtn(object sender, DataGridCommandEventArgs e)
    //{
    //    String courier_id = luckycourier_datagrid.DataKeys[e.Item.ItemIndex].ToString();
    //    String sqlCourierInfo = "SELECT code,name,fee_base,fee_rate from courier where id=" + courier_id;
    //    DataSet ds_courierinfo = DB.QuerySelect(sqlCourierInfo);
    //    String code = ds_courierinfo.Tables[0].Rows[0].ItemArray[0].ToString();
    //    String name = ds_courierinfo.Tables[0].Rows[0].ItemArray[1].ToString();
    //    float fee_base = float.Parse(ds_courierinfo.Tables[0].Rows[0].ItemArray[2].ToString());
    //    float fee_rate = float.Parse(ds_courierinfo.Tables[0].Rows[0].ItemArray[3].ToString());

    //    Button btn = (Button)luckycourier_datagrid.Items[e.Item.ItemIndex].FindControl("detail_button");
    //    if (btn.Text.Equals("结账"))
    //    {
    //        String sqlCheckOut = "UPDATE delivery SET checked=1 WHERE courier_id=" + courier_id;
    //        DB.QueryAlter(sqlCheckOut);
    //        detail_order_textbox.Text = name + " 已结清 " + DateTime.Now.ToShortDateString();
    //        return;
    //    }

    //    //String sqlDeliveryList = "SELECT sum(num * price) as sum_of_delivery, max(delivery_date) FROM delivery,orders,orders_category_dish,CategoryDish" +
    //    //                         " WHERE courier_id=" + courier_id + " and checked=0 " +
    //    //                         " AND orders.delivery_id=delivery.id and orders_id=orders.id " +
    //    //                         " AND categorydish_id=CategoryDish.id" +
    //    //                         " GROUP BY delivery.id";
    //    String sqlDeliveryList = "SELECT result_sum as sum_of_delivery, delivery_date from delivery where checked=0 and couried_id=" + courier_id;
    //    DataSet ds_deliverylist = DB.QuerySelect(sqlDeliveryList);

    //    String info = "序号 金额 日期\n";
    //    float sum = 0;
    //    int i = 0;
    //    for (i = 0; i < ds_deliverylist.Tables[0].Rows.Count; i++)
    //    {
    //        sum += float.Parse(ds_deliverylist.Tables[0].Rows[i].ItemArray[0].ToString());
    //        info += i + "\t" + ds_deliverylist.Tables[0].Rows[i].ItemArray[0].ToString() + " " +
    //            ds_deliverylist.Tables[0].Rows[i].ItemArray[1].ToString();
    //    }

    //    float total = i * fee_base + sum * fee_rate / 100;

    //    info += "总计:##############\n" + fee_base + "元 * " + i + "次 + " + sum + " * " + fee_rate + "% = " + total + "元";


    //    detail_order_textbox.Text = info;
    //}

    //protected void OnClickTotalBtn(object sender, EventArgs e)
    //{

    //    String info = "代号\t名字\t金额\t佣金\t尽盈余\n";
    //    float isum = 0;
    //    float itotal_fee = 0;
    //    int i = 0;

    //    for (i = 0; i < luckycourier_datagrid.DataKeys.Count; i++)
    //    {
    //        String courier_id = luckycourier_datagrid.DataKeys[i].ToString();

    //        String sqlCourierInfo = "SELECT code,name,fee_base,fee_rate from courier where id=" + courier_id;
    //        DataSet ds_courierinfo = DB.QuerySelect(sqlCourierInfo);
    //        String code = ds_courierinfo.Tables[0].Rows[0].ItemArray[0].ToString();
    //        String name = ds_courierinfo.Tables[0].Rows[0].ItemArray[1].ToString();
    //        float fee_base = float.Parse(ds_courierinfo.Tables[0].Rows[0].ItemArray[2].ToString());
    //        float fee_rate = float.Parse(ds_courierinfo.Tables[0].Rows[0].ItemArray[3].ToString());

    //        String sqlDeliveryList = "SELECT sum(num * price) as sum_of_delivery FROM delivery,orders,orders_category_dish,CategoryDish" +
    //                                 " WHERE courier_id=" + courier_id + " and datediff(day,delivery_date,getdate())=0 " +
    //                                 " AND orders.delivery_id=delivery.id and orders_id=orders.id " +
    //                                 " AND categorydish_id=CategoryDish.id" +
    //                                 " GROUP BY delivery.id";
    //        DataSet ds_deliverylist = DB.QuerySelect(sqlDeliveryList);


    //        float sum = 0;
    //        int j = 0;
    //        for (j = 0; j < ds_deliverylist.Tables[0].Rows.Count; j++)
    //        {
    //            sum += float.Parse(ds_deliverylist.Tables[0].Rows[j].ItemArray[0].ToString());
    //        }

    //        float total_fee = j * fee_base + sum * fee_rate / 100;

    //        info += code + "\t" + name + "\t" + sum + "\t" + total_fee + "\t" + (sum - total_fee) + "\n";

    //        isum += sum;
    //        itotal_fee += total_fee;
    //    }
    //    info += "总计:\n";
    //    info += "金额"+isum+"元 - 佣金"+itotal_fee+"元 = 总盈余"+(isum-itotal_fee)+"元";

    //    detail_order_textbox.Text = info;
    //}
}
